package jgl.vajra.management.part.home.fragment;

import android.view.View;

import com.orhanobut.logger.Logger;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import jgl.vajra.management.R;
import jgl.vajra.management.bean.HomeVehicleTypeBean;
import jgl.vajra.management.databinding.FragmentHomeVehicleTypeBinding;
import jgl.vajra.management.event.HomePageTypeEvent;
import jgl.vajra.management.manager.IntentManager;
import jgl.vajra.management.part.home.contract.HomeVehicleTypeContract;
import jgl.vajra.management.part.home.viewModel.HomeVehicleTypeViewModel;
import jgl.vajra.management.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.management.widget.mvvm.view.BaseMVVMFragment;

@CreateViewModel(HomeVehicleTypeViewModel.class)
public class HomeVehicleTypeFragment extends BaseMVVMFragment<HomeVehicleTypeViewModel, FragmentHomeVehicleTypeBinding> implements HomeVehicleTypeContract.View {

    private String title;
    private int icon;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_home_vehicle_type;
    }

    @Override
    public void initView() {
        mBinding.setView(this);


        int type = getArguments().getInt("type");
        String name = getArguments().getString("name");
        title = getArguments().getString("title");
        boolean isCalculator = getArguments().getBoolean("isCalculator");

        icon = R.drawable.ic_vehicle_details1;

        if (name.equals("挖掘机")) {
            icon = R.drawable.ic_vehicle_details1;
        } else if (name.equals("随车吊")) {
            icon = R.drawable.ic_vehicle_details;
        } else if (name.equals("低空炮")) {
            icon = R.drawable.ic_vehicle_details3;
        } else if (name.equals("专吊")) {
            icon = R.drawable.ic_vehicle_details4;
        } else if (name.equals("高空车")) {
            icon = R.drawable.ic_vehicle_details5;
        } else if (name.equals("叉车")) {
            icon = R.drawable.ic_vehicle_details6;
        }

        HomeVehicleTypeBean bean = new HomeVehicleTypeBean(true, icon);
        mBinding.setData(bean);

        Logger.d(name + "机械类型");
        mBinding.tvName.setText(name + "-" + title);

        if (!isCalculator) {
            mBinding.tvPriceCalculator.setVisibility(View.GONE);
        }
    }

    @Override
    public void initData() {

    }

    @Override
    public void initEvent() {

    }

    //价格计算器
    @Override
    public void onPriceCalculator() {
        IntentManager.toPriceCalculatorActivity(mActivity);
    }

    //带
    @Override
    public void onBelt() {
        HomeVehicleTypeBean bean = new HomeVehicleTypeBean(true, icon);
        mBinding.setData(bean);
    }

    //不带
    @Override
    public void onNoBelt() {
        HomeVehicleTypeBean bean = new HomeVehicleTypeBean(false, icon);
        mBinding.setData(bean);
    }

    //车型详情
    @Override
    public void onVehicleDetails(HomeVehicleTypeBean itemData) {
        IntentManager.toVehicleDetailsActivity(mActivity,itemData.icon);
    }

    @Override
    protected boolean isRegisterEvent() {
        return true;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onHomePageTypeEvent(HomePageTypeEvent event) {

        // mBinding.tvName.setText(event.name + "-" + title);
    }
}
